<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
    <link rel="stylesheet" id="pagestyle" type="text/css" href="easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
<title>TngouDB</title>
</head>
<body class="easyui-layout">
      

  <div data-options="region:'north'" style="height:38px">
    <div style="margin-top:10px;float:left;">TngouDB-中文全文搜索数据库</div>
  <div style="float:right;height:30px;margin-top:5px;"><span id="todayDate"></span><span id="sayHelloSpan"></span> 
  - 切换风格：<select class="easyui-combobox" id="tngou-themes">
  <option value="default" selected="selected">default</option>
  <option value="bootstrap">bootstrap</option>
  <option value="black">black</option>
  <option value="gray">gray</option>
  <option value="material">material</option>
  <option value="metro">metro</option>
  </select></div>
  
  <script type="text/javascript">
  
  $(document).ready(function(){
	  var themes=getCookie('themes');
	  if(themes){
		  document.getElementsByTagName("link")["pagestyle"].href = "easyui/themes/"+themes+"/easyui.css";
		  $('#tngou-themes').combobox('setValue', themes);
	  }
	  $("#sayHelloSpan").text(sayHello());
	  $("#todayDate").html(getToday());
	  setCookie('themes', 'default',365);
	 
   })
  
  	$('#tngou-themes').combobox({
  		onChange: function(value){
  			setCookie('themes', value,365);
  			 document.getElementsByTagName("link")["pagestyle"].href = "easyui/themes/"+value+"/easyui.css";
		 }
	});
  function setCookie(cname, cvalue, exdays) {
	    var d = new Date();
	    d.setTime(d.getTime() + (exdays*24*60*60*1000));
	    var expires = "expires="+d.toUTCString();
	    document.cookie = cname + "=" + cvalue + "; " + expires;
	}
	//获取cookie
	function getCookie(cname) {
	    var name = cname + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0; i<ca.length; i++) {
	        var c = ca[i];
	        while (c.charAt(0)==' ') c = c.substring(1);
	        if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
	    }
	    return "";
	}
    /**
	* 分时问候
	*/
	function sayHello(){
	var hour = new Date().getHours();
	var hello = '';
	if(hour < 6){
	hello='凌晨好';
	}else if(hour < 9){
	hello='早上好';
	}else if(hour < 12){
	hello='上午好';
	}else if(hour < 14){
	hello='中午好';
	}else if(hour < 17){
	hello='下午好';
	}else if(hour < 19){
	hello='傍晚好';
	}else if(hour < 22){
	hello='晚上好';
	}else{
	hello='夜里好';
	}
	return hello;
	}
	/**
	* 获得当天日期和星期
	*/
	function getToday(){
	WEEK_DATA_CN=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
	var today=new Date();
	var year = today.getFullYear();
	var month = today.getMonth()+1;
	month = month<10?'0'+month:month;
	var date = today.getDate();
	date = date<10?'0'+date:date;
	var day = WEEK_DATA_CN[today.getDay()];
	return year+"年"+month+"月"+date+"日 "+day;
	}
  
  </script>
  </div>
               
 <div data-options="region:'south'" style="height:50px;">
 <div style="text-align: center;margin-top: 5px;"> © 天狗.云(<a href="http://www.tngou.net" target="_blank">Tngou.NET</a>) | 成都天狗云科技有限版权所有     </div> </div>
 </div>
 
 <div data-options="region:'east',split:true" title="服务器信息" style="width:250px;">
         <form id="sysinfo" method="post">
         <div style="margin:5px 0;" >
                               刷新间隔时间：
            <select class="easyui-combobox" name="time" id="interval_time">
            <option value="1">1秒</option>
            <option value="3">3秒</option>
            <option value="5" selected="selected">5秒</option>
            <option value="10">10秒</option>
            <option value="15">15秒</option>
            <option value="30">30秒</option>
            <option value="60">60秒</option>
            </select>
              &nbsp;&nbsp;<ahref="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"
               onclick="sysinfoloadLocal()">手动刷新</a>
          </div>
           <div class="easyui-tabs">
           <div title="操作系统">
           <table cellpadding="5" >
                <tr>
                    <td>系统名称:</td>
                    <td><input  name="os_name" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
               <tr>
                    <td>体系结构:</td>
                    <td><input  name="os_arch" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
                 <tr>
                    <td>系统版本:</td>
                    <td><input  name="os_version" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
                <tr>
                    <td>CUP数目:</td>
                    <td><input  name="available_processors" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
                <tr>
                    <td>内存大小:</td>
                    <td><input  name="total_physical_memory_size" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
                  <tr>
                    <td>空闲内存:</td>
                    <td><input  name="free_physical_memory_size" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
                 <tr>
                    <td>交换空间:</td>
                    <td><input  name="total_swap_space_size" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
                <tr>
                    <td>可用空间:</td>
                    <td><input  name="free_swap_space_size" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
                 <tr>
                    <td>虚拟内存:</td>
                    <td><input  name="committed_virtual_memory_size" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
                </tr>
           
            </table>
           
           </div>
           
           <div title="线程信息">
           <table cellpadding="5" >               
             <tr>
                    <td>活动线程:</td>
                    <td><input  name="thread_count" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
              </tr>
                <tr>
                    <td>峰值计数:</td>
                    <td><input  name="daemon_thread_count" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
              </tr>
              <tr>
                    <td>峰值总数:</td>
                    <td><input  name="peak_thread_count" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
              </tr>
               <tr>
                    <td>运行总数:</td>
                    <td><input  name="thread_count" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
              </tr>
              <tr>
                    <td>运行时间:</td>
                    <td><input  name="current_thread_cpu_time" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
              </tr>
               <tr>
                    <td>用户时间:</td>
                    <td><input  name="current_thread_user_time" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
              </tr>  
            </table>
           
           </div>
           
            <div title="JRE信息">
           <table cellpadding="5" >               
                <tr>
                    <td>jvm信息:</td>
                    <td><input  name="jvm_info" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
               </tr>
               <tr>
                    <td>jvm名称:</td>
                    <td><input  name="jvm_name" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
               </tr>
               <tr>
                    <td>jvm供者:</td>
                    <td><input  name="jvm_vendor" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
               </tr>
                <tr>
                    <td>jvm版本:</td>
                    <td><input  name="jvm_specification_version" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
               </tr> 
                <tr>
                    <td>CLASS加载:</td>
                    <td><input  name="loaded_class_count" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
               </tr>
               <tr>
                    <td>CLASS总数:</td>
                    <td><input  name="total_loaded_class_count" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
               </tr>
               <tr>
                    <td>卸载CLASS:</td>
                    <td><input  name="un_loaded_class_count" class="easyui-textbox" type="text"  readonly="readonly"></input></td>
               </tr>
            </table>
           
           </div>
           
           </div>
            
        </form>
        <script type="text/javascript">
        var time ;
        var interval;
       
        $(document).ready(function(){
        	sysinfoloadLocal();
        	time=$("#interval_time").val();
        	interval = setInterval(sysinfoloadLocal,time*1000);

        });
        $('#interval_time').combobox({
        	onChange: function(newValue,oldValue){
        		clearInterval(interval);
        		time=newValue;
        		interval = setInterval(sysinfoloadLocal,time*1000);
        	}
        });
        function sysinfoloadLocal()
        {
        	$.getJSON("sysinfo",
        			function(item){
    	        	$('#sysinfo').form('load',item);
        	});
        }
        
       
        </script>
       
 
 </div>
 
 
 <div class="easyui-panel" data-options="region:'west',split:true" title="操作菜单" style="width:200px;">
    <div class="easyui-accordion" data-options="fit:true,border:false" >
    
       <div title="表(schema)"  data-options="
                selected:true,
                tools:[{
                    iconCls:'icon-reload',
                    handler:function(){
                        $('#tngou-tree').tree('reload');
                    }
                }]" >
               
        <ul class="easyui-tree"    id="tngou-tree" data-options="
                    url:'query?sql=schema',
                    method:'get',
                    animate:true,
                    lines:true,
                    formatter:function(node){
                        var s = node.name;  
                        return  '&nbsp;'+s;
                    }" >
           
        </ul>
      
 	</div>
 	<div  title="管理" style="padding:10px;">
 	
 	 <div style="padding:3px;"> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:100%">Search</a></div>
     <div style="padding:3px;"> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:100%">Search</a></div>
 
 	</div>
 </div>
 <script type="text/javascript">
 $('#tngou-tree').tree({
		onClick: function(node){
		   var title= node.name;
		   addTableTab(title);
		}
	});
 
 function addTableTab(title){
	// 通过标题来判定 该tab是否出现 如果出现，就选择该tab
	 if($("#tngou-tab").tabs("exists",title+" 表")){
	       $("#tngou-tab").tabs("select",title+" 表");    
	 }else{
		var sql="desc "+title;
		$.ajaxSettings.async = false; //同步执行
		var array =[{ field:'ck',checkbox:true }];
		var columns=[];
		$.getJSON("query?sql="+sql,
			function(item){
			var width= 100/item.length;
			$.each(item, function(i,item){
				array.push({field:item,title:item,width:width+"%",sortable:true});
			});
			
		});
		columns.push(array);
		$.ajaxSettings.async = true;//异步执行
		
		var html= '<table id="tngou_'+title+'" height="100%"></table>';
		$('#tngou-tab').tabs('add',{
			title: title+" 表",
			content:html,
			closable: true
			});
		}
	
	   $('#tngou_'+title).datagrid({
		   pagination:true,
		   method:'POST',
		   url: 'query',
		   pageSize:20,
		   queryParams: {'sql':'select * from '+title},
		   columns:columns
	   });
	}
 
 </script>
 </div>
 
 
     <div id="tngou-table-add" class="easyui-window" title="添加表" data-options="iconCls:'icon-table-add',modal:true,closed:true" 
     style="width:400px;height:200px;padding:10px;">
                <form id="tngou-table-form" method="post">
            <table cellpadding="5" width="100%">
                <tr>
                    <td>表名:</td>
                    <td><input id="tngou-table-add-name" class="easyui-textbox" type="text" name="name"  prompt="请输入表名"  style="width:280px" data-options="required:true"></input></td>
                </tr>
               
                <tr>
                    <td>SQL语句:</td>
                    <td><input id="tngou-table-add-sql" class="easyui-textbox" name="sql" data-options="multiline:true" style="height:60px;width:280px"  ></input></td>
                </tr>
               
            </table>
            <script type="text/javascript">	
            $('#tngou-table-add-name').textbox({
            	onChange: function(newValue,oldValue){
            		$('#tngou-table-add-sql').textbox('setValue',"create table "+newValue);	
            	}
            });
            function submitForm(){
            	var sql=$('#tngou-table-add-sql').textbox('getValue');
                $.messager.confirm('执行确认', '需要执行语句：<br>'+sql, function(r){
                    if (r){ 
                    	$.post("query",{sql:sql},
                    		function(item){
                    		 $.messager.alert('提示',item.msg);
                    		 if(item.status==200)
                    		{
                    			 $('#tngou-table-add').window('close');
                    			 $('#tngou-schema-table').datagrid('reload');
                    			 $('#tngou-tree').tree('reload');
                    		}
                			
                		});
                    }
                });
            }
            </script>   
                 </form>
         <div style="text-align:center;padding:5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">执行</a>
        </div>
    </div>

 	
        <div class="easyui-tabs" data-options="region:'center'" id="tngou-tab" >
          <div title="表(schema)" style="padding:10px">
              <script type="text/javascript">
		        var schematoolbar = [{
		            text:'打开表',
		            iconCls:'icon-table-go',
		            handler:function(){
		            	var rows=$('#tngou-schema-table').datagrid('getSelections');
		                if(rows.length==0)
			               {
			                   $.messager.alert("提示！","请选择需要打开的表！",'info')
			               }else
			               {
			            	   var name=rows[0]['name'];
			            	   addTableTab(name);
			               }	            	
		            	}
		        },'-',{
		            text:'添加表',
		            iconCls:'icon-table-add',
		            handler:function(){
		            	$('#tngou-table-add').window('open');
		            	}
		        },'-',{
		            text:'删除表',
		            iconCls:'icon-table-delete',
		            handler:function(){
		            	
		            	var rows=$('#tngou-schema-table').datagrid('getSelections');
		                if(rows.length==0)
			               {
			                   $.messager.alert("提示！","请选择需要删除的表！",'info')
			               }else
			               {
			            	   sql="drop table "+rows[0]['name'];
			            	   $.messager.confirm('执行确认', '需要执行语句：<br>'+sql,
			            		function(r){
			   					if (r){
			   						$.post("query",{sql:sql},
			   	                    		function(item){
			   	                    		 $.messager.alert('提示',item.msg);
			   	                    		 if(item.status==200)
			   	                    		{
			   	                    			 $('#tngou-schema-table').datagrid('reload');
			   	                    			 $('#tngou-tree').tree('reload');
			   	                    		}
			   	                			
			   	                		});
			   					}
			            	   });
			               }
		            	
		            }
		        },'-',{
		        	text:'刷新',
                    iconCls:'icon-table-refresh',
                    handler:function(){
                        $('#tngou-schema-table').datagrid('reload');
                    }
                }
		        
		        ];
		        
		        
		        function formatSize(value,row){
		        	if(value<1024){return value.toFixed(2)+" B";}
		        	value=value/1024;
		        	if(value<1024){return value.toFixed(2)+" KB";}
		        	value=value/1024;
		        	if(value<1024){return value.toFixed(2)+" MB";}
		        	value=value/1024;if(value<1024){return value.toFixed(2)+" GB";}     
		        }
		        
		       
		    </script>
           <table  class="easyui-datagrid" ,   id='tngou-schema-table'  height="100%"
             data-options="rownumbers:true,
             singleSelect:true,
             url:'query?sql=schema',
             method:'get',
             toolbar:schematoolbar
             ">
        <thead>
            <tr>
                <th data-options="field:'ck',checkbox:true"></th>
                <th field="name"  width="25%" sortable="true">名称</th>
                <th field="count" width="25%" align="center" sortable="true">行</th>
                <th field="size" width="45%" align="right" sortable="true" data-options="formatter:formatSize">大小</th>
                
            </tr>
        </thead>
            </table>
            <script type="text/javascript">
            
            $('#tngou-schema-table').datagrid({
            	onDblClickRow: function(index,row){
	            	addTableTab(row['name']);
	        	}
	        });
            </script>
        </div>
        </div>
  
  
</body>
</html>